home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 February: Tool Chest / Apple Developer CD Series Tool Chest February 1996 (Apple Computer)(1996).iso / Tool Chest / Testing & Debugging / General tools / Audit app & dcmd / Src / DisplayAudit.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-09-17  |  10.3 KB  |  391 lines  |  [TEXT/KAHL]

  1. /*                                    DisplayAudit.h                                */
  2. /*
  3.  * DisplayAudit.c
  4.  * Copyright © 1992-93, Apple Computer Inc. All Rights Reserved.
  5.  * Programmed by Martin Minow,
  6.  *    Internet:    minow@apple.com
  7.  *    AppleLink:    MINOW
  8.  * Version of January 22, 1993
  9.  *
  10.  * Edit History
  11.  *    93.01.09 MM        First public release
  12.  *    93.01.22 MM        Broke out from DisplayAudit.c
  13.  *    93.07.09 MM        Replaced simple text window by Log Manager and many other
  14.  *                    major revisions.
  15.  */
  16. /*
  17.  * Resource definitions
  18.  */
  19. #define ALRT_NonFatal        9000
  20. #define ALRT_Fatal            9001
  21. #define MBAR_MenuBar        1
  22. #define MENU_Apple            1
  23. #define MENU_File            256
  24. #define    MENU_Edit            257
  25. #define MENU_Font            258
  26. #define MENU_FontSize        259
  27. #define CNTL_FontPopup        256
  28. #define CNTL_SizePopup        257
  29. #define CNTL_TagButton        258
  30. #define WIND_Document        256
  31. #define DLOG_SFPutFile        4000
  32. #define DLOG_About            256
  33. #define STRN_Messages        128        /* Error messages                            */
  34. #define STRN_Strings        129        /* Random text strings                        */
  35. #define STRN_EditMenu        130        /* Undo text strings                        */
  36. #define STR_FinderString    128        /* Finder info string for param file        */
  37. /*
  38.  * Preference resource file information.
  39.  * kApplicationCreator    is the registered Application Creator ID.
  40.  * kDefaultAuditIdent    is the registered Application Creator ID for the sample
  41.  *                        CSAM - I used this because it's convenient (and that's
  42.  *                        what I'm debugging).
  43.  */
  44. #define kApplicationCreator        'MAM1'        /* Registered application creator    */
  45. #define kDefaultAuditIdent        'Pdsm'        /* kDSAMCreatorID                    */
  46. #define kPreferenceFileType        'pref'        /* Preference fileType                */
  47. #define PARM_ResourceID            1024        /* We'll create this resource        */
  48. #define STR_FinderIDString        (-16397)    /* Resource id of help message        */
  49. #define kNoParamFile            (-1)        /* Signal no parameter file created    */
  50. #define kDefaultAuditRecords    128            /* How many audit records to make    */
  51. #define kDefaultDisplayLines    512            /* How many lines to keep in memory    */
  52. #define kMinWindowWidth            200            /* Minimum width in pixels            */
  53. #define kMinWindowHeight        84            /* Minimum height in pixels            */
  54. #define kApplFontSize            9            /* For dialogs and buttons            */
  55. #define kScrollBarWidth            16
  56. #define kScrollBarOffset        (kScrollBarWidth - 1)
  57. #ifndef REZ
  58. #ifndef THINK_C
  59. #include <Errors.h>
  60. #include <Finder.h>
  61. #include <Folders.h>
  62. #include <Script.h>
  63. #include <Types.h>
  64. #include <Resources.h>
  65. #include <QuickDraw.h>
  66. #include <Fonts.h>
  67. #include <Events.h>
  68. #include <Windows.h>
  69. #include <Menus.h>
  70. #include <TextEdit.h>
  71. #include <Dialogs.h>
  72. #include <Desk.h>
  73. #include <ToolUtils.h>
  74. #include <Memory.h>
  75. #include <Files.h>
  76. #include <OSUtils.h>
  77. #include <OSEvents.h>
  78. #include <Printing.h>
  79. #include <DiskInit.h>
  80. #include <StandardFile.h>
  81. #include <Traps.h>
  82. #endif
  83. #include <GestaltEqu.h>
  84. #include <Packages.h>
  85. #include <Processes.h>
  86. #include "Audit.h"
  87. #include "Failure.h"
  88. #include "LogManager.h"
  89. #include "TextEditManager.h"
  90.  
  91. #ifndef TRUE
  92. #define TRUE        1
  93. #define FALSE        0
  94. #endif
  95. #ifndef EXTERN
  96. #define EXTERN        extern        /* Not in main program    */
  97. #endif
  98.  
  99. /*
  100.  * These are the "SleepTime" parameters for WaitNextEvent. The idea is that we
  101.  * sleep for a long time if we're in the background; for a short time if active.
  102.  */
  103. #define kForegroundTicks        6
  104. #define kBackgroundTicks        60
  105.  
  106. enum AppleMenu {
  107.     kAppleAbout            = 1
  108. };
  109.  
  110. enum FileMenu {
  111.     kFileNewWindow        = 1,
  112.     kFileCloseWindow,
  113.     kFileUnused1,
  114.     kFileSaveAs,
  115.     kFileCloseFile,
  116.     kFileUnused2,
  117.     kFilePageSetup,
  118.     kFilePrint,
  119.     kFileUnused3,
  120.     kFileTimeStamp,
  121.     kFileUnused4,
  122.     kFileQuit
  123. };
  124.  
  125. enum EditMenu {
  126.     kEditUndo            = 1,
  127.     kEditUnused,
  128.     kEditCut,
  129.     kEditCopy,
  130.     kEditPaste,
  131.     kEditClear
  132. };
  133.  
  134. /*
  135.  * Error alert messages. These are in resource (STR# STRN_Messages)
  136.  */
  137. enum {
  138.     kNoMessage                    = 0,
  139.     kErrInitialization,
  140.     kErrNoMemory,
  141.     kErrCreateAuditRecord,
  142.     kErrCreateTextWindow,
  143.     kErrSystemVersion,
  144.     kErrFindPreferenceFolder,
  145.     kErrFindPreferenceFile,
  146.     kErrOpenPreferenceFile,
  147.     kErrCreatePreferenceFile,
  148.     kErrWritePreferenceResource,
  149.     kErrReadPreferenceResource,
  150.     kErrCreateOutputFile,
  151.     kErrWriteOutputFile,
  152.     kErrCloseOutputFile,
  153.     kDummyLastMessage
  154. };
  155.     
  156. /*
  157.  * Random text messages. These are in resource ('STR#' STRN_Strings)
  158.  */
  159. enum {
  160.     kAuditParameterFileName        = 1,
  161.     
  162.     kDummyLastString
  163. };
  164.  
  165. /*
  166.  * This is the content of the Preferences file.
  167.  */
  168. typedef struct Parameters {
  169.     OSType                auditIdent;            /* Default Audit ident                */
  170.     long                enableAudit;        /* TRUE to start auditing            */
  171.     long                auditRecords;        /* Number of audit records             */
  172.     long                logDisplayLines;    /* Number of display lines            */
  173.     long                fontSize;            /* Font height in pixels            */
  174.     Str255                fontName;            /* User's chosen font                */
  175. } Parameters;
  176.  
  177. /*
  178.  * All document-specific variables are in this structure. This allows us to
  179.  * extend DisplayAudit so one application can watch several Audit Records.
  180.  */
  181. typedef struct DocumentRecord {
  182.     WindowRecord    windowRecord;            /* In this window - must be first    */
  183.     ListHandle        logListHandle;            /* Display log                        */
  184.     EditHandle        tagEditHandle;            /* TextEdit handle to "tag" audit    */
  185.     ControlHandle    tagButton;                /* Hit button to tag audit record    */
  186.     short            tagLine;                /* Bottom of button/text edit area    */
  187.     OSType            auditIdent;                /* Watching this audit record        */
  188.     AuditPtr        auditPtr;                /* Really watching this AuditRecord    */
  189.     AuditEntry        currentAuditEntry;        /* Working on this one                */
  190.     short            scanCount;                /* Equals number of Audit Records    */
  191.     unsigned long    totalMissedCount;        /* Total number of missed records    */
  192.     unsigned long    logIndex;                /* Current record being displayed    */
  193.     Boolean            enableAudit;            /* TRUE if auditing enabled            */
  194.     ProcessSerialNumber    oldPSN;                /* Previous DisplayAudit Process    */
  195.     short            logFileRefNum;            /* Writing to this file if non-zero    */
  196.     short            logFileVRefNum;            /* Writing to this volume            */
  197.     Str63            logFileName;            /* Writing to this named file        */
  198. } DocumentRecord, *DocumentPtr;
  199. /*
  200.  * All functions have a "documentPtr" parameter.
  201.  */
  202. #define DOC            (*documentPtr)
  203. #define WINDOW_PTR    ((WindowPtr) &DOC.windowRecord)
  204. #define WINDOW        (*WINDOW_PTR)
  205. #define ENTRY        (DOC.currentAuditEntry)
  206. #define IsOurWindow(theWindow) (                                \
  207.         (theWindow) != NULL                                        \
  208.         && ((WindowPeek) (theWindow))->windowKind == userKind    \
  209.     )
  210. /*
  211.  * AuditDocument.c: DisplayAudit Document Management
  212.  */
  213. void                                MakeDocumentWindow(void);
  214. void                                TimeStamp(
  215.         register DocumentPtr            documentPtr
  216.     );
  217. void                                ProcessAuditDocument(
  218.         register DocumentPtr            documentPtr
  219.     );
  220. void                                ProcessAuditEntry(
  221.         register DocumentPtr            documentPtr
  222.     );
  223. void                                DoWindowNullEvent(
  224.         register DocumentPtr            documentPtr
  225.     );
  226. void                                AdjustDocumentEditMenu(
  227.         register DocumentPtr            documentPtr
  228.     );
  229. void                                DoWindowKeyDown(
  230.         register DocumentPtr            documentPtr
  231.     );
  232. void                                DoContentClick(
  233.         register DocumentPtr            documentPtr
  234.     );
  235. void                                UpdateDocumentWindow(
  236.         register DocumentPtr            documentPtr
  237.     );
  238. void                                DoDocumentEditMenu(
  239.         register DocumentPtr            documentPtr,
  240.         short                            menuItem
  241.     );
  242. void                                ActivateDocumentWindow(
  243.         register DocumentPtr            documentPtr,
  244.         Boolean                            isActivating
  245.     );
  246. void                                DisposeDocumentWindow(
  247.         register DocumentPtr            documentPtr
  248.     );
  249. void                                DecorateWindow(
  250.         register DocumentPtr            documentPtr
  251.     );
  252. void                                DoDocumentSaveAs(
  253.         register DocumentPtr            documentPtr
  254.     );
  255. void                                DoDocumentCloseFile(
  256.         register DocumentPtr            documentPtr
  257.     );
  258.  
  259. /*
  260.  * WindowUtilities.c
  261.  */
  262. Boolean                                DoGrowWindow(
  263.         register WindowPtr                theWindow,
  264.         short                            minWindowWidth,
  265.         short                            minWindowHeight
  266.     );
  267. void                                DoZoomWindow(
  268.         register WindowPtr                theWindow,
  269.         short                            whichPart
  270.     );
  271. /*
  272.  * AuditFileDialog.c
  273.  */
  274. void                                AuditFileDialog(
  275.         short                            dialogID,
  276.         ConstStr255Param                promptString,
  277.         ConstStr255Param                originalName,
  278.         SFReply                            *reply
  279.     );
  280.  
  281. /*
  282.  * DisplayAuditFile.c
  283.  */
  284. /*
  285.  * File functions
  286.  */
  287. void                                PromptAndCreateAuditOutputFile(
  288.         ConstStr255Param                promptString,
  289.         ConstStr255Param                defaultFileName,
  290.         OSType                            creator,
  291.         short                            *fileRefNum,
  292.         short                            *volumeRefNum,
  293.         Str63                            fileName
  294.     );
  295. OSErr                                CreateOutputFile(
  296.         OSType                            creator,
  297.         ConstStr255Param                fileName,
  298.         short                            vRefNum,
  299.         short                            *fileRefNum
  300.     );
  301. void                                WriteAuditOutputLine(
  302.         ConstStr255Param                theText,
  303.         short                            fileRefNum
  304.     );
  305. void                                CloseAuditOutputFile(
  306.         OSErr                            status,
  307.         short                            fileRefNum,
  308.         short                            volumeRefNum,
  309.         ConstStr255Param                fileName
  310.     );
  311.  
  312. /*
  313.  * DisplayAuditPreferences.c
  314.  */
  315. void                                OpenAuditParameterFile(void);
  316. void                                ReadAuditParameters(void);
  317. void                                WriteAuditParameters(void);
  318. void                                ParameterFactorySettings(void);
  319. OSErr                                SearchForCreatorType(
  320.         short                            prefVRefNum,
  321.         long                            prefDirID,
  322.         Str63                            trueFileName
  323.     );
  324.  
  325. void                                ErrorAlert(
  326.         OSErr                            status,
  327.         short                            messageIndex,
  328.         Boolean                            fatal
  329.     );
  330.  
  331. #define height(box)                (box.bottom - box.top)
  332. #define width(box)                (box.right - box.left)
  333. /*
  334.  * Cheap 'n dirty pascal string copy routine.
  335.  */
  336. #define pstrcpy(dst, src) do {                            \
  337.         StringPtr    _src = (src);                        \
  338.         BlockMove(_src, dst, _src[0] + 1);                \
  339.     } while (0)
  340. /*
  341.  * Cheap 'n dirty pascal string concat.
  342.  */
  343. #define pstrcat(dst, src) do {                            \
  344.         StringPtr        _dst = (dst);                    \
  345.         StringPtr        _src = (src);                    \
  346.         short            _len;                            \
  347.         _len = 255 - _dst[0];                            \
  348.         if (_len > _src[0]) _len = _src[0];                \
  349.         BlockMove(&_src[1], &_dst[1] + _dst[0], _len);    \
  350.         _dst[0] += _len;                                \
  351.     } while (0)
  352. /*
  353.  * Cheap 'n dirty memory clear routine.
  354.  */
  355. #define CLEAR(record) do {                                \
  356.         register char    *ptr = (char *) &record;        \
  357.         register long    size;                            \
  358.         for (size = sizeof record; size > 0; --size)    \
  359.             *ptr++ = 0;                                    \
  360.     } while (0)
  361.  
  362. /*
  363.  * Globals
  364.  */
  365. EXTERN EventRecord            gEventRecord;
  366. #define    EVENT                (gEventRecord)
  367. EXTERN Parameters            gParameterRecord;
  368. #define PARM                (gParameterRecord)
  369. EXTERN short                gParameterFileRefNum;
  370. EXTERN short                gOpenWindowCount;
  371. EXTERN Boolean                gInForeground;
  372. EXTERN Boolean                gParameterUpdateNeeded;
  373. EXTERN Boolean                gUpdateMenusNeeded;
  374. EXTERN short                gWindowOffset;
  375. EXTERN Boolean                gHasColorQuickDraw;
  376. /*
  377.  * We only want to set the old PSN once. Otherwise, there's a risk of garbling
  378.  * the Audit PSN if the user closes windows in a different order.
  379.  */
  380. EXTERN Boolean                gHaveOldPSN;            /* gOldPSN set already        */
  381. EXTERN ProcessSerialNumber    gMyPSN;
  382. EXTERN Boolean                gQuitNow;
  383. EXTERN MenuHandle            gAppleMenu;
  384. EXTERN MenuHandle            gFileMenu;
  385. EXTERN MenuHandle            gEditMenu;
  386. EXTERN MenuHandle            gFontMenu;
  387. EXTERN MenuHandle            gFontSizeMenu;
  388. EXTERN THPrint                gPrintHandle;
  389.  
  390. #endif /* REZ */
  391.